
package vmcs.utility;

/**
 * Title:        VMCS
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:      ISS
 * @author Pang Pingli
 * @version 1.0
 */


import java.util.HashMap;
import java.util.Map;

import vmcs.entity.CashStoreItem;
import vmcs.entity.Coin;
import vmcs.entity.StoreItem;
import vmcs.factory.CloneableObjectEnum;
import vmcs.factory.ObjectRegistry;

public class CashPropertyLoader extends PropertyLoader {

  public CashPropertyLoader(String filen) {
    super(filen);
  }

  /*public CashStoreItem getItem(int idx){
    CashStoreItem   cit;

    Coin cn = new Coin();
    String  item, itemv;

    item = new String("Name" + idx);
    itemv = getValue(item);
    cn.setName(itemv);

    item = new String("Weight" + idx);
    itemv = getValue(item);
    cn.setWeight(Double.parseDouble(itemv));

    item = new String("Value" + idx);
    itemv = getValue(item);
    cn.setValue(Integer.parseInt(itemv));

    item = new String("Quantity" + idx);
    itemv = getValue(item);

    cit = new CashStoreItem(cn, Integer.parseInt(itemv));

    return cit;
  }*/

  public StoreItem getItem(int idx) {
	  
	    CashStoreItem   cit;

	    Map<String,String> params=new HashMap<String, String>();
	    
	    String  item, itemv;

	    item = new String("Name" + idx);
	    itemv = getValue(item);
	    params.put("name", itemv);
	    
	    item = new String("Weight" + idx);
	    itemv = getValue(item);
	    params.put("weight", itemv);

	    item = new String("Value" + idx);
	    itemv = getValue(item);
	    params.put("value", itemv);
	    
	    /*Coin coin = (Coin)StoreObjectRegistry.lookup(StoreObjectEnum.COIN);
	    coin.initialize(params);
	    Coin coin = (Coin)StoreObjectFactory.createStoreObject(StoreObjectEnum.COIN, params);*/
	    
	    
	    Coin coin = (Coin)ObjectRegistry.lookup(CloneableObjectEnum.COIN);
	    coin.initialize(params);
	    
	    item = new String("Quantity" + idx);
	    itemv = getValue(item);

	    cit = new CashStoreItem(coin, Integer.parseInt(itemv));
	    //System.out.println("ToString" +("Idx :"+idx+ "\nCashstore item "+cit));
	    
	    return cit;
  }
  
  
  public void setItem(int it, StoreItem item){
    String  itn;
    int  itemv;
    String  its;
    Coin  cn;
    int idx = it + 1;

    cn = (Coin) item.getContent();
    itn = new String("Name" + idx);

    setValue(itn, cn.getName());

    itn = new String("Weight" + idx);
    setValue(itn, String.valueOf(cn.getWeight()));

    itn = new String("Value" + idx);
    setValue(itn, String.valueOf(cn.getValue()));

    itn = new String("Quantity" + idx);
    setValue(itn, String.valueOf(item.getQuantity()));
  }

}